<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片区 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8" >
          <!-- 搜索框 -->
          <el-input placeholder="请输入内容" clearable v-model="queryData.query" @clear="getOrderList"  >
            <el-button slot="append" @click="searchGoods" icon="el-icon-search" type="primary"></el-button>
          </el-input>
        </el-col>
      </el-row>
    <!-- 表格区域 -->
    <el-table  style="width: 100%" :data="orderList" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="order_number" label="订单编号" width="350px"></el-table-column>
      <el-table-column prop="order_price" label="订单价格" width="250px"></el-table-column>
      <el-table-column prop="pay_status" label="是否付款" width="250px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.pay_status==0" type="danger">未付款</el-tag>
          <el-tag v-else type="success">已付款</el-tag>

        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货"></el-table-column>
      <el-table-column prop="update_time" label="下单时间" width="200px">
        <template slot-scope="scope">
          {{ scope.row.add_time | dateFormat }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作">
        <template>
        <el-button type="primary" size="mini" icon="el-icon-edit" @click="showEditAddress"></el-button>
        <el-button type="success" size="mini" icon="el-icon-location" @click="showProgressDialog"></el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <!-- 页码条区域 -->
    <el-pagination @size-change="handleSizeChange" :page-size="5" @current-change="pageChange"
      :current-page="queryData.pagenum" :page-sizes="[1, 3, 5, 10]"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>

    <!-- 修改地址对话框 -->
    <!-- <el-dialog title="修改地址" :visible.sync="isEditAddressShow" width="50%">
      <el-cascader
        v-model="selectCityIds"
        :options="cityList"
        :props="{ expandTrigger: 'hover' }"
        ></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isEditAddressShow = false">取 消</el-button>
        <el-button type="primary" @click="editAddress">确 定</el-button>
      </span>
    </el-dialog> -->

    <!--  物流进度对话框
    <el-dialog
    v-dialogDrag title="物流进度" :visible.sync="isshowProgressDialog" width="50%">
     物流进度
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in wuliuProgress"
          :key="index"
          :timestamp="activity.ftime"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog> -->
    </el-card>
  </div>
</template>

<script>
// import cityList from './citydata.js'

export default {
  data () {
    return {
      orderList: [],
      queryData: {
        query: '', // 查询关键字
        pagenum: 1, // 当前页码
        pagesize: 5 // 当前页容量
      },
      total: 0
      // isEditAddressShow:false,
      // cityList,
      // selectCityIds:[],
      // isshowProgressDialog:false,
      // wuliuProgress:[]
    }
  },
  created () {
    this.getOrderList()
  },
  methods: {
    // async showProgressDialog(){
    //   // 请求 物流数据
    //   let {data:res} = await this.$http.get('kuaidi/110697571266')
    //    if (res.meta.status != 200) this.$message.error('请求物流信息错误~！')
    //   //如果成功
    //   // 挂载数据到data中，供视图使用
    //   this.wuliuProgress = res.data
    //   // 显示 物流对话框
    //   this.isshowProgressDialog = true
    // },
    // showEditAddress(){
    //   this.isEditAddressShow = true
    // },
    // editAddress(){
    //   this.isEditAddressShow = false
    // },
    handleSizeChange (newSize) {
      // 拿到最新的页容量
      this.queryData.pagesize = newSize
      this.getOrderList()
    },
    pageChange (newPage) {
      this.queryData.pagenum = newPage
      this.getOrderList()
    },
    async getOrderList () {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryData
      })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败')
      this.orderList = res.data.goods
      this.total = res.data.total
    },
    // 查询商品
    searchGoods () {
      // 去掉两边空格，
      this.queryData.query = this.queryData.query.trim()
      this.getOrderList()
    }
  }
}
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 15px;
}
.el-cascader{
  width: 100%;
}
</style>
